From: Ivan Kozlovic Date: Tue, 12 Jul 2022 16:22:53 +0000 (-0600) Subject: [PATCH] [FIXED] Compiler warning for JSON get time X-Git-Tag: archive/raspbian/3.4.1-1+rpi1~3 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=0b9e0bb9c5e1965cd6af8d45b5e02067cb1c0706;p=nats.c.git [PATCH] [FIXED] Compiler warning for JSON get time When formatting a date/time, the max lenght is 35 characters, so the backing array should be 36 at least (for the terminal '\0'). Signed-off-by: Ivan Kozlovic Gbp-Pq: Name 208f27a8ccd80bbadba4409b68fb5fe308b97c56.patch --- diff --git a/src/util.c b/src/util.c index bd770eb..0501860 100644 --- a/src/util.c +++ b/src/util.c @@ -1292,8 +1292,8 @@ nats_JSONGetTime(nats_JSON *json, const char *fieldName, int64_t *timeUTC) char utcOff[7] = {'\0'}; int64_t nanosecs = 0; char *p = NULL; - char orgStr[35] = {'\0'}; - char timeStr[35] = {'\0'}; + char orgStr[36] = {'\0'}; + char timeStr[36] = {'\0'}; char offSign = '+'; int offHours = 0; int offMin = 0; @@ -1319,7 +1319,7 @@ nats_JSONGetTime(nats_JSON *json, const char *fieldName, int64_t *timeUTC) l = (int) strlen(str); // The smallest date/time should be: "YYYY:MM:DDTHH:MM:SSZ", which is 20 // while the longest should be: "YYYY:MM:DDTHH:MM:SS.123456789-12:34" which is 35 - if ((l < 20) || (l > (int) sizeof(timeStr))) + if ((l < 20) || (l > (int) (sizeof(timeStr) - 1))) { if (l < 20) s = nats_setError(NATS_INVALID_ARG, "time '%s' too small", str);